package ms.db.mongodb;

import org.bson.BsonBinary;
import org.bson.BsonTimestamp;
import org.bson.json.Converter;
import org.bson.json.StrictJsonWriter;
import org.bson.types.Decimal128;
import org.bson.types.ObjectId;

public class DataConverter {
	public static class ObjectIdConverter implements Converter<ObjectId> {

		@Override
		public void convert(ObjectId value, StrictJsonWriter writer) {
			writer.writeString(value.toString());
		}
	}
	
	public static class Decimal128Converter implements Converter<Decimal128> {

		@Override
		public void convert(Decimal128 value, StrictJsonWriter writer) {
			writer.writeNumber(value.toString());
		}
	}
	
	public static class DoubleConverter implements Converter<Double>{

		@Override
		public void convert(Double value, StrictJsonWriter writer) {
			writer.writeNumber(value.toString());
		}
	}

	public static class Int64Converter implements Converter<Long>{

		@Override
		public void convert(Long value, StrictJsonWriter writer) {
			writer.writeNumber(value.toString());
		}
	}
	
	public static class Int32Converter implements Converter<Integer>{

		@Override
		public void convert(Integer value, StrictJsonWriter writer) {
			writer.writeNumber(value.toString());
		}
	}
	
	public static class BinaryConverter implements Converter<BsonBinary>{

		@Override
		public void convert(BsonBinary value, StrictJsonWriter writer) {
			writer.writeNumber(value.toString());
		}
	}

	public static class TimestampConverter implements Converter<BsonTimestamp> {

		@Override
		public void convert(BsonTimestamp value, StrictJsonWriter writer) {
			writer.writeNumber(String.valueOf(value.getValue()));
		}		
	}
	
	public static class JsonDateTimeConverter implements Converter<Long> {

		@Override
		public void convert(Long value, StrictJsonWriter writer) {
			writer.writeNumber(String.valueOf(value));			
		}
	}
}